/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CreateNewCusPanel.java
 *
 * Created on 2011-11-3, 15:34:06
 */
package view.frontoperator;

import business.CreateNewCusCmd;
import javax.swing.JOptionPane;
import model.Customer;

/**
 *
 * @author Administrator
 */
public class CreateNewCusPanel extends javax.swing.JPanel {

    /** Creates new form CreateNewCusPanel */
    public CreateNewCusPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sexBtnGroup = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        idField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        nameField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        maleBtn = new javax.swing.JRadioButton();
        femaleBtn = new javax.swing.JRadioButton();
        confirmBtn = new javax.swing.JButton();

        jLabel1.setText("身份证号");
        jLabel1.setName("jLabel1"); // NOI18N

        idField.setName("idField"); // NOI18N

        jLabel3.setText("姓名");
        jLabel3.setName("jLabel3"); // NOI18N

        nameField.setName("nameField"); // NOI18N

        jLabel4.setText("性别");
        jLabel4.setName("jLabel4"); // NOI18N

        sexBtnGroup.add(maleBtn);
        maleBtn.setSelected(true);
        maleBtn.setText("男");
        maleBtn.setName("maleBtn"); // NOI18N

        sexBtnGroup.add(femaleBtn);
        femaleBtn.setText("女");
        femaleBtn.setName("femaleBtn"); // NOI18N

        confirmBtn.setText("确定");
        confirmBtn.setName("confirmBtn"); // NOI18N
        confirmBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(134, 134, 134)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(nameField)
                        .addComponent(confirmBtn, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(maleBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(femaleBtn)))
                .addContainerGap(173, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(154, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(maleBtn)
                    .addComponent(femaleBtn))
                .addGap(29, 29, 29)
                .addComponent(confirmBtn)
                .addGap(144, 144, 144))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void confirmBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmBtnActionPerformed
        Customer customer = new Customer();
        CreateNewCusCmd cmd = new CreateNewCusCmd();
        cmd.setCustomer(customer);
        customer.setId(idField.getText());
        customer.setMale(maleBtn.isSelected()?true:false);
        customer.setName(nameField.getText());
        if( cmd.execute(null) ) {
            JOptionPane.showMessageDialog(this, "创建新顾客信息成功 ", "成功", JOptionPane.INFORMATION_MESSAGE);
        }else{
            JOptionPane.showMessageDialog(this, "创建新顾客信息失败 ", "错误", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_confirmBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton confirmBtn;
    private javax.swing.JRadioButton femaleBtn;
    private javax.swing.JTextField idField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JRadioButton maleBtn;
    private javax.swing.JTextField nameField;
    private javax.swing.ButtonGroup sexBtnGroup;
    // End of variables declaration//GEN-END:variables
}
